#ifndef WINDOWS_H
#define WINDOWS_H

#include <string>
#include <vector>
#include <SDL/SDL.h>

#include "RGB.h"
//#include "Buttons.h"

#ifndef WINDOW_STYLES
#define WINDOW_STYLES

    #define NO_FRAMES   0
    #define FRAME_LEFT  1
    #define FRAME_RIGHT 2
    #define FRAME_UP    4
    #define FRAME_DOWN  8
    #define ALL_FRAMES  15
    
#endif //WINDOW_STYLES


enum  DRAWINGMODE {
    Background,
    Normal
};

struct Button {
    int pressed;
    
    int x, y;
    int w, h;
};

struct Pixel {
    Pixel(int _x, int _y, int _w, int _h):
        x(_x), y(_y), w(_w), h(_h) {}
    int x;
    int y;
    int w;
    int h;
};

class Window {
    
    public:
        
        friend class WindowsMenager;
        
        Window(const char* name, int style, int size_w, int size_h, int (*MClick)(int,int,int));
        Window(const Window& w);
        
        ~Window() {
            SDL_FreeSurface(Surface);
        }            
        
    private:
        
        int Resize(int size_w, int size_h);
        int Clear();
        
        SDL_Surface* Surface; //pointer to SurfaceBackground or SurfaceAll
        SDL_Surface* SurfaceBackground; //background
        SDL_Surface* SurfaceAll; //background with sprites, etc. (ready to draw)
        int w, h;
        
        int xSrc, ySrc;    
        int xDest, yDest;
        int wDest, hDest;      
        
        std::string Name;
        
        int (*MouseClick)(int, int, int);
        
        DRAWINGMODE DrawingMode;      
        std::vector<Pixel> vPixels;
        
        int Style;
        
        struct {
            Button DownL;
            Button DownR;
            Button RightU;
            Button RightD;
        }Buttons;
};


class WindowsMenager {
    
    public:
        
        int AddWindow(const char* name, int style, int w, int h, int (*MClick)(int,int,int));
        int AddWindow(const char* name, int style, int (*MClick)(int,int,int));  
        int AddWindow(const char* name);
        
        int Resize(const char* name, int w, int h);
        int DrawPixel(const char* name, int color, int x, int y, int w=1, int h=1);
        
        int MouseClick(int x, int y, int b);
        int MouseUp();
        int IsMouseOnWindow(const char* name);
        int GetMouseState(const char* name, int* x, int *y);
        
        int DrawAll();
        int DrawFrame(const char* name, int color, int x, int y, int w, int h);
        
        int GetW(const char* name);
        int GetH(const char* name);
        
        int SetSrcX(const char* name, int x);
        int SetSrcY(const char* name, int y);   
        int SetDestX(const char* name, int x);
        int SetDestY(const char* name, int y);
        int SetDestW(const char* name, int w);
        int SetDestH(const char* name, int h);
        
        int StartDrawingBackground(const char* name);
        int StopDrawingBackground(const char* name);
        
        int Clear();
        int Clear(int x, int y, int w, int h);
        int Clear(const char* name);          
               
    private:
        
        int MakeWindow(const char* name, int style, int w, int h, int (*MClick)(int,int,int));   
        int Search(const char* name);
      
        std::vector<Window> vWindows;
        
        int Time; //for frames
        
};

#endif //WINDOWS_H
